package com.bwie.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbMenu;
import com.bwie.service.TbMenuService;
import com.bwie.mapper.TbMenuMapper;
import com.bwie.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 28242
* @description 针对表【tb_menu(权限表)】的数据库操作Service实现
* @createDate 2025-05-21 15:59:15
*/
@Service
public class TbMenuServiceImpl extends ServiceImpl<TbMenuMapper, TbMenu>
    implements TbMenuService{

    @Autowired
    TbMenuMapper tbMenuMapper;
    @Override
    public List getMenuList(Integer userId) {
      List<TbMenu> list=  tbMenuMapper.getMenuList(userId);


        List<Tree<String>> treeList = TreeUtil.build(list, "0", (menu, tree) -> {
            tree.setId(menu.getMenuId() + "");
            tree.setName(menu.getMenuName());
            tree.setParentId(menu.getMenuPid() + "");

            tree.putExtra("menuPath", menu.getMenuPath());
        });

        return treeList;
    }
}




